package com.cangjie.xiaozhi

import org.junit.Test
import org.junit.Assert.*

class XiaozhiToolWindowTest {
    
    @Test
    fun `test html content generation for single line`() {
        val htmlContent = generateHtmlContent("val x = 10")
        assertEquals("<p>val x = 10</p>", htmlContent)
    }
    
    @Test
    fun `test html content generation for multiple lines`() {
        val input = """
            fun main() {
                println("Hello, World!")
            }
        """.trimIndent()
        
        val expected = "<p>fun main() {</p><p>    println(\"Hello, World!\")</p><p>}</p>"
        val htmlContent = generateHtmlContent(input)
        assertEquals(expected, htmlContent)
    }
    
    @Test
    fun `test html content generation with special characters`() {
        val input = "if (x < 10 && y > 5) { return x & y; }"
        val expected = "<p>if (x &lt; 10 &amp;&amp; y &gt; 5) { return x &amp; y; }</p>"
        val htmlContent = generateHtmlContent(input)
        assertEquals(expected, htmlContent)
    }
    
    @Test
    fun `test html content generation with empty lines`() {
        // 测试真正的空行（没有任何字符）
        val input = "Line 1\n\nLine 3"
        val expected = "<p>Line 1</p><p></p><p>Line 3</p>"
        val htmlContent = generateHtmlContent(input)
        assertEquals(expected, htmlContent)
    }
    
    @Test
    fun `test xiaozhi url constant`() {
        // 测试URL常量是否正确设置
        val expectedUrl = "https://yuanbao.tencent.com/bot/app/agent/cmmKveGl8ACU"
        assertEquals(expectedUrl, XiaozhiToolWindowFactory.XIAOZHI_URL)
    }
    
    /**
     * 模拟XiaozhiToolWindow中的HTML内容生成逻辑
     */
    private fun generateHtmlContent(message: String): String {
        val lines = message.split("\n")
        return lines.joinToString("") { line ->
            "<p>${line.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")}</p>"
        }
    }
}